
* Setup 
clear all

* Formatting
graph set window fontface "Times New Roman"	// use Times New Roman as the default font for Graph window
// 	 graph set window fontface default 			// use this to restore to factury setting if preferred later

set scheme s1mono


********************************************************************
*************** Figure 1: plotting treatment effects ***************

use "${ddata}cleaned_data_wACSweight.dta", clear 

forvalues i=0(1)5 {

	reg qs2_`i' treatment [aweight=weight_ACS], robust

	matrix q`i' = r(table)

	gen p_`i'= q`i'[4,1]

}

keep userid qs2_* p_* treatment sce weight_ACS

reshape long qs2_ p_, i(userid sce treatment weight_ACS) j(questions)
 	
rename qs2_ answers
rename p_ p_value

collapse (mean) mean= answers p_value (sd) sd=answers (count) n=answers [aweight=weight_ACS], by(question treatment)

generate hiwrite = mean + invttail(n-1,0.025)*(sd / sqrt(n))
generate lowrite = mean - invttail(n-1,0.025)*(sd / sqrt(n))

generate q_t = 1    if question==0&treatment==0
replace  q_t = 2    if question==0&treatment==1
replace  q_t = 4    if question==1&treatment==0
replace  q_t = 5    if question==1&treatment==1
replace  q_t = 7    if question==2&treatment==0
replace  q_t = 8    if question==2&treatment==1
replace  q_t = 10   if question==3&treatment==0
replace  q_t = 11   if question==3&treatment==1
replace  q_t = 13   if question==4&treatment==0
replace  q_t = 14   if question==4&treatment==1
replace  q_t = 16   if question==5&treatment==0
replace  q_t = 17   if question==5&treatment==1

sort q_t

gen 	position=1.5  if question==0
replace position=4.5  if question==1
replace position=7.5  if question==2
replace position=10.5 if question==3
replace position=13.5 if question==4
replace position=16.5 if question==5


gen _plotp = ""

forvalues i=0(1)5 {

	egen  	max_`i' = max(mean) 	if question==`i'
	gen   	ppv_`i' = p_value 		if question==`i'
	egen  	pv_`i'  = max(ppv_`i')

	local p`i': display %4.3f pv_`i' 			 	 //store p-value with correct formating in local macro
	replace  _plotp = "p=`p`i''" 	if question==`i' //store p-value with brackets as string variable

}


gen y=.

forvalues i=0(1)5 {

	replace y=max_`i'+5 if question==`i'

}


twoway (bar mean q_t if treatment==0 ) ///
	(bar mean q_t if treatment==1 ) ///
	(scatter  y position, msym(none) mlab(_plotp) mlabp(12) mlabc(black) mlabs(vsmall)) ///
	(rcap hiwrite lowrite q_t), ///
	legend( order(1 "Control" 2 "Treatment" )) legend(size(12pt) ) ///
	xlabel( 1.5 "Mother reject offer" 4.5 "15% less" 7.5 "Same" 10.5 "15% more" 13.5 "30% more" 16.5 "50% more", noticks  labsize(small)) ///
	ylabel(0(10)80,labsize(small)) yscale(r(0 70)) ///
	xtitle("   Mother makes", size(small)) legend(region(lstyle(none)) size(small)) ytitle("Probability recommends conservative action", size(small)) 

graph export "${o}f1_weights.pdf", replace
